<!-- 阅卷管理 -->

<template>
  <div>
    <div style="padding: 10px 0">
      <el-popconfirm
          icon="el-icon-warning"
          icon-color="red"
          :title="BatchDeletion_info"
          :confirm-button-text='Ok'
          :cancel-button-text='Cancel'
          @confirm="delBatch"
      >
        <el-button icon="el-icon-circle-close" type="danger" slot="reference" :disabled="flag">
          {{ $t('main.BatchDeletion') }}
        </el-button>
      </el-popconfirm>
    </div>

    <el-table border :data="tableData" stripe :header-cell-style="{background:'#DCDCDC',color:'#0f0f0f'}"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50"></el-table-column>
      <el-table-column prop="id" label="ID" width="80" sortable>
      </el-table-column>
      <el-table-column label="考试名称">
        <template v-slot="scope">
          <span v-for="item in exams" v-if="item.id == scope.row.examId">{{ item.name }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="studentId" label="学生">
        <template v-slot="scope">
          <span v-for="item in students" v-if="item.id == scope.row.studentId">{{ item.username }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="time" label="提交时间">
      </el-table-column>
      <el-table-column prop="score" label="得分">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button type="primary" @click="$router.push('/Tea_CorrectingPapers?sp=' + scope.row.id)">阅卷</el-button>
          <el-popconfirm
              icon="el-icon-warning"
              icon-color="red"
              :title="Delete_info"
              :confirm-button-text='Ok'
              :cancel-button-text='Cancel'
              @confirm="deleteHandle(scope.row.id)"
          >
            <el-button style="margin-left: 5px" slot="reference" icon="el-icon-remove-outline" type="danger">
              {{ $t('main.Delete') }}
            </el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <div style="padding: 10px 0;text-align: right">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[3, 5, 10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "Management_Marking",
  created() {
    this.LanguageMethod()
    this.load()
  },
  data() {
    return {
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 10,
      input: '',
      form: {},
      exams: [],
      students: [],
      multipleSelection: [],
      flag: true,
      // 当前语言
      currentLanguage: '',
      // 确定按钮
      Ok: '',
      // 取消按钮
      Cancel: '',
      // 表信息
      Table_info: '',
      // 删除信息
      Delete_info: '',
      // 批量删除信息
      BatchDeletion_info: '',
      // 搜索信息
      Search_info: '',
      // 标题，成功信息
      Title_Success_info: '',
      // 标题，失败信息
      Title_Error_info: '',
      // 删除成功消息
      Delete_Success_Message: '',
      // 删除失败消息
      Delete_Error_Message: '',
      // 操作成功信息
      Save_Success_Message: '',
      // 操作失败信息
      Save_Error_Message: '',
      // 批量删除成功信息
      DelBatch_Success_Message: '',
      // 批量删除失败信息
      DelBatch_Error_Message: '',
    }
  },
  methods: {
    // 请求后台数据
    load() {
      this.request.get("/s-p/page", {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize
        }
      }).then(res => {
        this.tableData = res.records
        this.total = res.total
      })

      this.request.get("/exam").then(res => {
        this.exams = res
      })

      this.request.get("/student").then(res => {
        this.students = res
      })
    },
    // 总页数
    handleSizeChange(pageSize) {
      this.pageSize = pageSize
      this.load()
    },
    // 当前页
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum
      this.load()
    },
    // 删除
    deleteHandle(id) {
      this.request.delete("/s-p/" + id).then(res => {
        if (res) {
          this.$message.success(this.Delete_Success_Message)
          this.load()
        } else {
          this.$message.error(this.Delete_Error_Message)
        }
      })
    },
    // 新增或编辑时点击确定，保存数据
    save() {
      this.request.post("/s-p", this.form).then(res => {
        if (res) {
          this.$message.success(this.Save_Success_Message)
          this.load()
        } else {
          this.$message.error(this.Save_Error_Message)
        }
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
      // 当选择数据时，开启批量删除按钮
      if (this.multipleSelection.length === 0) {
        this.flag = true
      }
      // 没有选择数据，禁用批量删除按钮
      else {
        this.flag = false
        this.multipleSelection = val
      }
    },
    // 批量删除
    delBatch() {
      // 将对象数组转int数组
      let ids = this.multipleSelection.map(v => v.id)
      this.request.post("/e-p/del/batch", ids).then(res => {
        if (res) {
          this.$message.success(this.DelBatch_Success_Message)
          this.load()
        } else {
          this.$message.error(this.DelBatch_Error_Message)
        }
      })
    },
    // 语言设置
    LanguageMethod() {
      // 获取当前语言
      this.currentLanguage = localStorage.getItem('lang');

      // 中文
      if (this.currentLanguage === 'Chinese') {
        this.Ok = this.$i18n.messages.Chinese.main.Ok
        this.Cancel = this.$i18n.messages.Chinese.main.Cancel
        this.Table_info = this.$i18n.messages.Chinese.main.Table_info
        this.Delete_info = this.BatchDeletion_info = this.$i18n.messages.Chinese.main.Delete_info
        this.BatchDeletion_info = this.$i18n.messages.Chinese.main.BatchDeletion_info
        this.Search_info = this.$i18n.messages.Chinese.main.Search_info
        this.Title_Success_info = this.$i18n.messages.Chinese.main.Title_Success_info
        this.Title_Error_info = this.$i18n.messages.Chinese.main.Title_Error_info
        this.Delete_Success_Message = this.$i18n.messages.Chinese.main.Delete_Success
        this.Delete_Error_Message = this.$i18n.messages.Chinese.main.Delete_Error
        this.Save_Success_Message = this.$i18n.messages.Chinese.main.Save_Success
        this.Save_Error_Message = this.$i18n.messages.Chinese.main.Save_Error
        this.DelBatch_Success_Message = this.$i18n.messages.Chinese.main.DelBatch_Success
        this.DelBatch_Error_Message = this.$i18n.messages.Chinese.main.DelBatch_Error
        this.ImportFile_Success_Message = this.$i18n.messages.Chinese.main.ImportFile_Success
        this.ImportFile_Error_Message = this.$i18n.messages.Chinese.main.ImportFile_Error
      }
      // 英语
      else if (this.currentLanguage === 'English') {
        this.Ok = this.$i18n.messages.English.main.Ok
        this.Cancel = this.$i18n.messages.English.main.Cancel
        this.Table_info = this.$i18n.messages.English.main.Table_info
        this.Delete_info = this.BatchDeletion_info = this.$i18n.messages.English.main.Delete_info
        this.BatchDeletion_info = this.$i18n.messages.English.main.BatchDeletion_info
        this.Search_info = this.$i18n.messages.English.main.Search_info
        this.Title_Success_info = this.$i18n.messages.English.main.Title_Success_info
        this.Title_Error_info = this.$i18n.messages.English.main.Title_Error_info
        this.Delete_Success_Message = this.$i18n.messages.English.main.Delete_Success
        this.Delete_Error_Message = this.$i18n.messages.English.main.Delete_Error
        this.Save_Success_Message = this.$i18n.messages.English.main.Save_Success
        this.Save_Error_Message = this.$i18n.messages.English.main.Save_Error
        this.DelBatch_Success_Message = this.$i18n.messages.English.main.DelBatch_Success
        this.DelBatch_Error_Message = this.$i18n.messages.English.main.DelBatch_Error
        this.ImportFile_Success_Message = this.$i18n.messages.English.main.ImportFile_Success
        this.ImportFile_Error_Message = this.$i18n.messages.English.main.ImportFile_Error
      }
      // 日语
      else if (this.currentLanguage === 'Japanese') {
        this.Ok = this.$i18n.messages.Japanese.main.Ok
        this.Cancel = this.$i18n.messages.Japanese.main.Cancel
        this.Table_info = this.$i18n.messages.Japanese.main.Table_info
        this.Delete_info = this.BatchDeletion_info = this.$i18n.messages.Japanese.main.Delete_info
        this.BatchDeletion_info = this.$i18n.messages.Japanese.main.BatchDeletion_info
        this.Search_info = this.$i18n.messages.Japanese.main.Search_info
        this.Title_Success_info = this.$i18n.messages.Japanese.main.Title_Success_info
        this.Title_Error_info = this.$i18n.messages.Japanese.main.Title_Error_info
        this.Delete_Success_Message = this.$i18n.messages.Japanese.main.Delete_Success
        this.Delete_Error_Message = this.$i18n.messages.Japanese.main.Delete_Error
        this.Save_Success_Message = this.$i18n.messages.Japanese.main.Save_Success
        this.Save_Error_Message = this.$i18n.messages.Japanese.main.Save_Error
        this.DelBatch_Success_Message = this.$i18n.messages.Japanese.main.DelBatch_Success
        this.DelBatch_Error_Message = this.$i18n.messages.Japanese.main.DelBatch_Error
        this.ImportFile_Success_Message = this.$i18n.messages.Japanese.main.ImportFile_Success
        this.ImportFile_Error_Message = this.$i18n.messages.Japanese.main.ImportFile_Error
      }
      // 韩语
      else if (this.currentLanguage === 'Korean') {
        this.Ok = this.$i18n.messages.Korean.main.Ok
        this.Cancel = this.$i18n.messages.Korean.main.Cancel
        this.Table_info = this.$i18n.messages.Korean.main.Table_info
        this.Delete_info = this.BatchDeletion_info = this.$i18n.messages.Korean.main.Delete_info
        this.BatchDeletion_info = this.$i18n.messages.Korean.main.BatchDeletion_info
        this.Search_info = this.$i18n.messages.Korean.main.Search_info
        this.Title_Success_info = this.$i18n.messages.Korean.main.Title_Success_info
        this.Title_Error_info = this.$i18n.messages.Korean.main.Title_Error_info
        this.Delete_Success_Message = this.$i18n.messages.Korean.main.Delete_Success
        this.Delete_Error_Message = this.$i18n.messages.Korean.main.Delete_Error
        this.Save_Success_Message = this.$i18n.messages.Korean.main.Save_Success
        this.Save_Error_Message = this.$i18n.messages.Korean.main.Save_Error
        this.DelBatch_Success_Message = this.$i18n.messages.Korean.main.DelBatch_Success
        this.DelBatch_Error_Message = this.$i18n.messages.Korean.main.DelBatch_Error
        this.ImportFile_Success_Message = this.$i18n.messages.Korean.main.ImportFile_Success
        this.ImportFile_Error_Message = this.$i18n.messages.Korean.main.ImportFile_Error
      }
      // 俄语
      else if (this.currentLanguage === 'Russian') {
        this.Ok = this.$i18n.messages.Russian.main.Ok
        this.Cancel = this.$i18n.messages.Russian.main.Cancel
        this.Table_info = this.$i18n.messages.Russian.main.Table_info
        this.Delete_info = this.BatchDeletion_info = this.$i18n.messages.Russian.main.Delete_info
        this.BatchDeletion_info = this.$i18n.messages.Russian.main.BatchDeletion_info
        this.Search_info = this.$i18n.messages.Russian.main.Search_info
        this.Title_Success_info = this.$i18n.messages.Russian.main.Title_Success_info
        this.Title_Error_info = this.$i18n.messages.Russian.main.Title_Error_info
        this.Delete_Success_Message = this.$i18n.messages.Russian.main.Delete_Success
        this.Delete_Error_Message = this.$i18n.messages.Russian.main.Delete_Error
        this.Save_Success_Message = this.$i18n.messages.Russian.main.Save_Success
        this.Save_Error_Message = this.$i18n.messages.Russian.main.Save_Error
        this.DelBatch_Success_Message = this.$i18n.messages.Russian.main.DelBatch_Success
        this.DelBatch_Error_Message = this.$i18n.messages.Russian.main.DelBatch_Error
        this.ImportFile_Success_Message = this.$i18n.messages.Russian.main.ImportFile_Success
        this.ImportFile_Error_Message = this.$i18n.messages.Russian.main.ImportFile_Error
      }
      // 德语
      else if (this.currentLanguage === 'German') {
        this.Ok = this.$i18n.messages.German.main.Ok
        this.Cancel = this.$i18n.messages.German.main.Cancel
        this.Table_info = this.$i18n.messages.German.main.Table_info
        this.Delete_info = this.BatchDeletion_info = this.$i18n.messages.German.main.Delete_info
        this.BatchDeletion_info = this.$i18n.messages.German.main.BatchDeletion_info
        this.Search_info = this.$i18n.messages.German.main.Search_info
        this.Title_Success_info = this.$i18n.messages.German.main.Title_Success_info
        this.Title_Error_info = this.$i18n.messages.German.main.Title_Error_info
        this.Delete_Success_Message = this.$i18n.messages.German.main.Delete_Success
        this.Delete_Error_Message = this.$i18n.messages.German.main.Delete_Error
        this.Save_Success_Message = this.$i18n.messages.German.main.Save_Success
        this.Save_Error_Message = this.$i18n.messages.German.main.Save_Error
        this.DelBatch_Success_Message = this.$i18n.messages.German.main.DelBatch_Success
        this.DelBatch_Error_Message = this.$i18n.messages.German.main.DelBatch_Error
        this.ImportFile_Success_Message = this.$i18n.messages.German.main.ImportFile_Success
        this.ImportFile_Error_Message = this.$i18n.messages.German.main.ImportFile_Error
      }
      // 法语
      else if (this.currentLanguage === 'French') {
        this.Ok = this.$i18n.messages.French.main.Ok
        this.Cancel = this.$i18n.messages.French.main.Cancel
        this.Table_info = this.$i18n.messages.French.main.Table_info
        this.Delete_info = this.BatchDeletion_info = this.$i18n.messages.French.main.Delete_info
        this.BatchDeletion_info = this.$i18n.messages.French.main.BatchDeletion_info
        this.Search_info = this.$i18n.messages.French.main.Search_info
        this.Title_Success_info = this.$i18n.messages.French.main.Title_Success_info
        this.Title_Error_info = this.$i18n.messages.French.main.Title_Error_info
        this.Delete_Success_Message = this.$i18n.messages.French.main.Delete_Success
        this.Delete_Error_Message = this.$i18n.messages.French.main.Delete_Error
        this.Save_Success_Message = this.$i18n.messages.French.main.Save_Success
        this.Save_Error_Message = this.$i18n.messages.French.main.Save_Error
        this.DelBatch_Success_Message = this.$i18n.messages.French.main.DelBatch_Success
        this.DelBatch_Error_Message = this.$i18n.messages.French.main.DelBatch_Error
        this.ImportFile_Success_Message = this.$i18n.messages.French.main.ImportFile_Success
        this.ImportFile_Error_Message = this.$i18n.messages.French.main.ImportFile_Error
      }
    }
  }
}
</script>